var roleBuilderout = {

    /** @param {Creep} creep **/
    run: function(creep) {
        //creep.say(creep.memory.building);  //说话测试
        //creep.say(creep.memory.building);

        if(creep.store.getUsedCapacity()==0){
            creep.memory.building = true;
        }
        else{
            creep.memory.building = false;
        }


        if(creep.memory.building == true){
            if(creep.room.name != 'E9S58'){
                //creep.say(321);
                creep.moveTo(Game.flags['Flag10'].pos);
            }
            else{
                var targetsgo = creep.room.find(FIND_STRUCTURES, {
                    filter: (structure) => {
                        return structure.structureType == STRUCTURE_STORAGE && structure.store.getUsedCapacity() > 0;
                    }
                });
                if(targetsgo.length > 0) {
                    if(creep.withdraw(targetsgo[0], RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) {
                        creep.moveTo(targetsgo[0]);
                        //creep.say('建来');    //说话测试
                    }
                }   
            }

            
        }
        else{
            if(creep.room.name != 'E9S57'){
                //creep.say(321);
                creep.moveTo(Game.flags['Flag9'].pos);
            }
            else{
                //creep.say(321321);
                var targets = creep.room.find(FIND_CONSTRUCTION_SITES);
                if(targets.length > 0) {
                    if(creep.build(targets[0]) == ERR_NOT_IN_RANGE) {
                        creep.moveTo(targets[0]);
                        //creep.say('建去');    //说话测试
                    }
                }
            }
        }
        
	}
};

module.exports = roleBuilderout;